package com.rxw.nutmall.product.controller;

import com.rxw.nutmall.page.PageData;
import com.rxw.nutmall.product.entity.CategoryBrandRelation;
import com.rxw.nutmall.product.service.CategoryBrandRelationService;
import com.rxw.nutmall.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌分类关联 前端控制器
 * </p>
 *
 * @author 咸蛋超人
 * @since 2024-01-17
 */
@RestController
@RequestMapping("/product/categoryBrandRelation")
@AllArgsConstructor
@Api(tags = "品牌分类关联")
public class CategoryBrandRelationController {
    private CategoryBrandRelationService categoryBrandRelationService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageData<CategoryBrandRelation>> findPage(@RequestParam Map<String, Object> params) {
        PageData<CategoryBrandRelation> page = categoryBrandRelationService.page(params);
        return Result.ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询")
    public Result<CategoryBrandRelation> get(@PathVariable("id") Long id) {
        CategoryBrandRelation data = categoryBrandRelationService.get(id);
        return Result.ok(data);
    }

    @GetMapping("/getList")
    @ApiOperation("批量查询")
    public Result<List<CategoryBrandRelation>> getList(@RequestBody CategoryBrandRelation dto) {
        List<CategoryBrandRelation> data = categoryBrandRelationService.getList(dto);
        return Result.ok(data);
    }


    @PostMapping("/save")
    @ApiOperation("报存")
    public Result<Object> save(@RequestBody CategoryBrandRelation dto) {
        String id = categoryBrandRelationService.save(dto);
        return Result.ok(id);
    }

    @PostMapping("/saveList")
    @ApiOperation("批量报存")
    public Result<Object> saveList(@RequestBody List<CategoryBrandRelation> list) {
        categoryBrandRelationService.saveList(list);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public Result<Object> delete(@PathVariable Long id) {
        categoryBrandRelationService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/del/batch")
    @ApiOperation("批量删除")
    public Result<Object> deleteList(@RequestBody List<Long> idList) {
        categoryBrandRelationService.removeList(idList);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("修改")
    public Result<Object> update(@RequestBody CategoryBrandRelation dto) {
        categoryBrandRelationService.update(dto);
        return Result.success();
    }

    @PutMapping("/update/batch")
    @ApiOperation("批量修改")
    public Result<Object> updateList(@RequestBody List<CategoryBrandRelation> list) {
        categoryBrandRelationService.updateList(list);
        return Result.success();
    }
}
